package com.e.dianshang.controller;


import com.e.dianshang.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: HP
 * Date: 2020/11/10 18:09
 * Description:
 */
@RestController
@RequestMapping("/goods")
@Api(value = "执行商品管理的控制器",tags = "商品管理接口的api")
public class GoodsController {

    JsonResult jsonResult = new JsonResult();

    // 添加商品
    @ApiOperation(value = "商品添加的接口",notes = "添加商品",httpMethod = "POST",response = String.class)
    @RequestMapping(value = "/insert",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map insert(@RequestBody Map map){

//        map.put("商品名称","华硕飞行堡垒7");
//        map.put("商品描述","飞行堡垒，玩家首选");
//        map.put("商品价格","7000");
//        jsonResult.put("goods",map);

        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");

        return jsonResult.getValues();
    }

    // 修改商品
    @ApiOperation(value = "商品修改的接口",notes = "修改商品",httpMethod = "POST",response = String.class)
    @RequestMapping(value = "/update",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map update(@RequestBody Map map){

        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");

        return jsonResult.getValues();
    }

    // 删除商品（批量删除）
    @ApiOperation(value = "商品删除或批量删除的接口",notes = "删除或批量删除商品",httpMethod = "POST",response = String.class)
    @RequestMapping(value = "/deleteBatch",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map deleteBatch(@RequestBody Map<String, List> m){

        List ids = m.get("id");

        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");

        return jsonResult.getValues();
    }

    // 分页查询
    @ApiOperation(value = "商品分页的接口",notes = "查询所有商品并分页",httpMethod = "GET",response = String.class)
    @RequestMapping(value = "/findByPage",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map findByPage(@RequestParam("page")Integer page,@RequestParam("limit")Integer limit){

        // 调用pagehelper

        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");

        return jsonResult.getValues();
    }

    // 修改商品上下架状态
    @ApiOperation(value = "商品上下架的接口",notes = "修改商品上下架状态",httpMethod = "GET",response = String.class)
    @RequestMapping(value = "/updateManageState",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map updateManageState(@RequestParam("id")int id,@RequestParam("state")boolean state){

        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");

        return jsonResult.getValues();
    }

}
